package com.zyh.stream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author zyh
 * @Date 2024/8/5 10:42
 * @Description 写入一个字符的方法
 */

public class StreamDemo1 {
    //读入一个字符
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("D:\\course\\02-JavaSE进阶\\day09-IO流\\素材\\a.txt");
        /*int read1 = fis.read();
        System.out.println("read1 = " + ((char) read1));
        int read2 = fis.read();
        System.out.println("read2 = " + read2);
        int read3 = fis.read();
        System.out.println("read3 = " + read3);*/
        int len;
        //使用循环来读
        while ((len=fis.read())!=-1){

            /*if (len==-1){
                break;
            }*/
            System.out.print(((char) len));
        }
    }
    //写入一个字符的方法
    public static void main1(String[] args) throws IOException {
        String name="Hello Stream";
        FileOutputStream fos = new FileOutputStream("D:\\course\\02-JavaSE进阶\\day09-IO流\\素材\\a.txt");
        byte[] bytes = name.getBytes();
        for (byte aByte : bytes) {
            fos.write(aByte);
        }
        //关流
        fos.close();
    }
}
